<template>
	<view class="pageStyle">
		<g-watermark/>
		<public-list ref="publicListShow" :params="queryParam" :listRecord="model" nativeTo="/application/moduleShow"
			nativeToEdit="/application/moduleAddEdit"></public-list>
	</view>
</template>
<script>
	import PublicList from "./publicList.vue";
	export default {
		components: {
			PublicList
		},
		data() {
			return {
				describe: "模块列表",
				model: {},
				queryParam: {
					moduleCode: "",
				},
				isDoRefresh: false,
				isReadShow: false,
			};
		},
		onLoad(options) {
			console.log('options.record', options.record);
			this.model = JSON.parse(options.record);
			console.log('model', this.model);
			this.queryParam.moduleCode = this.model.code;
			this.queryParam.formCode = this.model.formCode;
			// 操作列模块型按钮带入的模块 ID
			this.queryParam.moduleId = this.model.moduleId;
			this.queryParam.treeNodeCode = this.model.treeNodeCode;
			// 点赞的主模块
			this.queryParam.mainModuleCode = this.model.mainModuleCode;
			this.search();
			
			// 初始化updatePage事件
			uni.$off('updatePage')
			uni.$on('updatePage',(data) => {
				this.search()
			})
		},
		onShow() {
			if (!this.isReadShow) {
				this.isReadShow = true;
			} else {
				// 防止每次进入界面时刷新
				// this.search();
			}

			const that = this;
			let pages = getCurrentPages();
			//刷新页面
			let currPage = pages[pages.length - 1];
			if (currPage.isDoRefresh == true) {
				currPage.isDoRefresh = false;
				that.search();
			}
		},
		//新增完之后刷页面
		// onShow(e) {
		//   const that = this;
		//   let pages = getCurrentPages();
		//   //刷新页面
		//   let currPage = pages[pages.length - 1];
		//   if (currPage.isDoRefresh == true) {
		//     currPage.isDoRefresh = false;
		//     that.search();
		//   }
		// },
		//下拉刷新
		onPullDownRefresh() {
			// #ifdef MP-WEIXIN
			this.search();
			wx.stopPullDownRefresh();
			// #endif

			// #ifdef APP-ANDROID || H5
			uni.startPullDownRefresh();
			this.search();
			uni.stopPullDownRefresh();
			// #endif

			// #ifdef APP-IOS
			this.search();
			uni.stopPullDownRefresh();
			// #endif
		},
		//上滑动刷新
		onReachBottom() {
			this.$refs.publicListShow.getOnReachBottom();
		},
		created() {
			// 小程序中不支持
			// window.search = this.search;
		},
		methods: {
			search() {
				setTimeout(() => {
					this.$refs.publicListShow.search();
				}, 200);
			},
		},
	};
</script>
<style lang="scss" scoped>
	.pageStyle {
		height: 100%;
	}
</style>